package su.api.mock.controller;

import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import su.api.mock.config.ApiSwitch;
import su.api.mock.config.ApiSwitchKeys;
import su.api.mock.dto.ExecProjectConflictDto;
import su.api.mock.dto.ExecProjectConflictResult;


@RestController
public class TestController {

    @ApiSwitch(key = ApiSwitchKeys.EXEC_PROJECT_CONFLICT, fallbackClass = TestController.class, fallbackMethod = "execProjectConflictMock")
    @PostMapping("/feign/project/projectConflict/execProjectConflict")
    public ExecProjectConflictResult execProjectConflict(@RequestBody List<ExecProjectConflictDto> execProjectConflictDtoList) {
        return new ExecProjectConflictResult(execProjectConflictDtoList.stream().findAny().get().getProject(), "success");
    }

    @GetMapping("/feign/project/getExecProjectConflict")
    @ApiSwitch(key = ApiSwitchKeys.GET_EXEC_PROJECT_CONFLICT, fallbackClass = TestController.class, fallbackMethod = "getExecProjectConflictMock")
    public String getExecProjectConflict(@RequestParam String project) {
        return "success";
    }


    @GetMapping("/getExecProjectConflictWithPath/{projectName}")
    @ApiSwitch(key = ApiSwitchKeys.GET_EXEC_PROJECT_CONFLICT_WITH_PATH, fallbackClass = TestController.class, fallbackMethod = "getExecProjectConflictMock")
    public String getExecProjectConflictWithPath(@PathVariable("projectName") String projectName) {
        return "success";
    }


    @ApiSwitch(key = ApiSwitchKeys.EXEC_PROJECT_CONFLICT, fallbackClass = MockApi.class, fallbackMethod = "execProjectConflictMock")
    @PostMapping("/feign/project/projectConflict/execProjectConflictOtherMock")
    public ExecProjectConflictResult execProjectConflictOtherMock(@RequestBody List<ExecProjectConflictDto> execProjectConflictDtoList) {
        return new ExecProjectConflictResult(execProjectConflictDtoList.stream().findAny().get().getProject(), "success");
    }

    @GetMapping("/getExecProjectConflictWithPathOtherMock/{projectName}")
    @ApiSwitch(key = ApiSwitchKeys.GET_EXEC_PROJECT_CONFLICT_WITH_PATH, fallbackClass = MockApi.class, fallbackMethod = "getExecProjectConflictMock")
    public String getExecProjectConflictWithPathOtherMock(@PathVariable("projectName") String projectName) {
        return projectName + "success";
    }

    public ExecProjectConflictResult execProjectConflictMock(List<ExecProjectConflictDto> execProjectConflictDtoList) {
        return new ExecProjectConflictResult("mock", "mock");
    }

    public String getExecProjectConflictMock(String project) {
        return "mock";
    }

}
